package com.cyz.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.cj.xdevapi.Statement;

/**
 * �������ݿ�
 * @author asus
 *
 */
public class Dbutil {
		private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
		private static final String URL="jdbc:mysql://localhost:3306/shopping?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true";
		private static final String USER = "root";
		private static final String PWD = "123456";

		// �޷���ʾ��ʵ����
		private void DbConnection() {

		}

		// ��������
		static {
			try {
				Class.forName(DRIVER);
			} catch (ClassNotFoundException e) {
				System.out.println("���������쳣");
			}
		}

		/** ��ȡ���ݿ����� */
		public static Connection getConnection() {
			Connection conn = null;
			try {
				conn = DriverManager.getConnection(URL, USER, PWD);
			} catch (SQLException e) {
				e.printStackTrace();
				System.out.println("��ȡ���ݿ������쳣");
			}
			return conn;
		}

		/** �ر������Դ */
		public static void close(Connection conn) {
			close(conn, null, null);
		}

		public static void close(Connection conn, Statement stmt) {
			close(conn, stmt, null);
		}

		public static void close(Connection conn, Statement stmt, ResultSet rs) {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
				}
			}

			if (stmt != null) {
				try {
					((Connection) stmt).close();
				} catch (SQLException e) {
				}
			}
		}

}